package com.wunong.smart.collection.service;

import com.wunong.smart.collection.client.dto.CollectionDTO;
import com.wunong.smart.collection.client.query.CollectionQueryDTO;
import com.wunong.smart.collection.client.service.CollectionReadService;
import com.wunong.smart.collection.repository.CollectionRepository;
import com.wunong.smart.domain.platform.common.BizSource;
import com.wunong.smart.domain.platform.rpc.Result;

import javax.annotation.Resource;
import java.util.List;

import static com.wunong.smart.collection.converter.CollectionModelConverter.toDto;

/**
 * @author create by zealot.zt
 */
public class CollectionReadServiceImpl implements CollectionReadService {

    @Resource
    protected CollectionRepository collectionRepository;

    @Override
    public Result<CollectionDTO> getById(Long id) {
        return Result.create(toDto(collectionRepository.getById(id)));
    }

    @Override
    public Result<CollectionDTO> getById(Long userId, Long id) {
        return Result.create(toDto(collectionRepository.getById(userId, id)));
    }

    @Override
    public Result<List<CollectionDTO>> queryByBiz(BizSource source) {
        return Result.create(toDto(collectionRepository.queryByBiz(source)));
    }

    @Override
    public Result<CollectionDTO> getByUserIdAndBiz(Long userId, BizSource source) {
        return Result.create(toDto(collectionRepository.getByUserIdAndBiz(userId, source)));
    }

    @Override
    public Result<List<CollectionDTO>> query(CollectionQueryDTO queryDTO) {
        return Result.create(toDto(collectionRepository.query(queryDTO)));
    }

}
